yjx.filter('dateTrans', ['$filter', function ($filter) {

    /*前端时间显示分4种：X分钟前、X小时前、1天前、2天前、超过两天的显示日期*/
    var dateTrans = function (date, format) {
        var dateP = date

        var now = new Date().valueOf();
        var onedaybefore = now - 24 * 60 * 60 * 1000;
        var twodaybefore = now - 24 * 60 * 60 * 2 * 1000;
        var threedaybefore = now - 24 * 60 * 60 * 3 * 1000;
        var hourBefore = now - 60 * 60 * 1000;

        if (dateP <= twodaybefore && threedaybefore < dateP) {
            return "2天前"
        }
        if (dateP <= threedaybefore) {
            return $filter('date')(date, format)
        }
        if (dateP <= onedaybefore && twodaybefore < dateP) {
            return "1天前"
        }
        if ( dateP <= hourBefore && onedaybefore < dateP ) {
            var h = parseInt((now - dateP) / (60 * 60 * 1000))
            return h + "小时前"
        }
        if (hourBefore < dateP ) {
            var m = parseInt((now - dateP) /( 60 * 1000));
            return m + "分钟前"
        }

    }
    return dateTrans;
    
}]);